package com.environment.unit;


import com.jme.scene.Node;

/**
 * <code>Component</code> implements <code>IComponent</code> interface to provide
 * an abstraction of a component unit.
 * <p>
 * <code>Component</code> extends <code>Node</code> so that it can be attached
 * directly to scene graph for rendering.
 * 
 * @author Yi Wang (Neakor)
 * @version Creation date: 04-12-08 18:52 EST
 * @version Modified date: 05-23-08 15:48 EST
 */
public abstract class Component extends Node implements IComponent{
	/**
	 * Serial version.
	 */
	private static final long serialVersionUID = -7519415631343386551L;
	/**
	 * Flag indicates if this <code>Component</code> is active.
	 */
	protected boolean active;
	
	/**
	 * Constructor of <code>Component</code>.
	 */
	public Component(String name) {
		super(name);
		this.active = true;
	}
	
	@Override
	public void initialize() {
		if(this.validate()) this.initializeDetail();
	}
	
	/**
	 * Initialize the details of this <code>Component</code>.
	 */
	protected abstract void initializeDetail();
	
	@Override
	public void update(float time) {
		if(this.active) {
			this.updateDetail(time);
		}
	}

	/**
	 * Update the details of this <code>Component</code>.
	 * @param time The current time of the environment in 24 hour time system.
	 */
	protected abstract void updateDetail(float time);
	
	@Override
	public void setActive(boolean active) {
		this.active = active;
	}
	
	@Override
	public boolean isActive() {
		return this.active;
	}
}
